package com.wallet.provider.service.impl;

import com.github.pagehelper.Page;
import com.wallet.common.vo.PageResult;
import com.wallet.provider.mapper.RoleMapper;
import com.wallet.provider.model.Role;
import com.wallet.provider.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public PageResult<Role> getRoleList(String keywords, int pageNum, int pageSize, String orderName, String orderType) {
        Page<Role> roles = roleMapper.selectByPageNumSize(keywords,pageNum, pageSize,orderName, orderType);
        return PageResult.getPageResult(roles);
    }

    @Override
    public Boolean addRole(Role role) {
        role.setCreateTime(new Date());
        role.setCreateBy("admin");
        return roleMapper.insertSelective(role) > 0;

    }

    @Override
    public Boolean deleteRole(String ids) {
        return roleMapper.deleteByIds(ids)>0;

    }

    @Override
    public Role getRoleById(Long id) {
        return roleMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Role> getRoleByUserId(Long id) {
        return null;
    }


    @Override
    public Boolean updateRole(Role role) {
        role.setUpdateTime(new Date());
        role.setUpdateBy("admin");
        return roleMapper.updateByPrimaryKeySelective(role) > 0;
    }

    @Override
    public List<Role> getAllRoleList() {
        return  roleMapper.getAllRoleList();
    }
}
